package com.woniuxy.dao;

import java.sql.*;

public class ManagerDao {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //如果你的驱动只有一个，就是只连接mysql 那么这个可以省略
        Class.forName("com.mysql.jdbc.Driver");//反射 技术
        System.out.println("连接数据库，加载驱动中……");
        //提供一个数据库连接, 可以连接到数据库
        String url = "jdbc:mysql://127.0.0.1:3306/student?useUnicode=true&characterEncoding=UTF8&useSSL=false";
        Connection connection = DriverManager.getConnection(url,"root","123456");
        System.out.println(connection);
        System.out.println("成功连上数据库！");
        //创建一个编译对象
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("select * from stuinfo");
        while (resultSet.next()) {
            int anInt = resultSet.getInt(1);
            System.out.print("id: "+anInt+"   ");
            String name = resultSet.getString("name");
            System.out.print("字段name的值："+name);
            int sex = resultSet.getInt("sex");
            System.out.println("性别id：" + sex);
        }
        connection.close();
    }
}
